package cn.script.util;

import cn.script.app.start.AppLogOut;
import cn.script.call_api.OutLogApi;

import java.util.Formatter;
import java.util.Locale;

/**
 * 日志输出
 *
 * @author 周永波
 */
public class LogOut {

    private final static LogOut OUT = new LogOut();


    private OutLogApi outLogApi = new OutLogApi() {
        @Override
        public void out(String val) {
            AppLogOut.out(val);
        }
    };


    public static void setOutLogApi(OutLogApi outLogApi) {
        OUT.outLogApi = outLogApi;
    }

    public static void out(String str, Object... formats) {
        OUT.out_(str, formats);
    }

    public synchronized void out_(String str, Object... formats) {
        String val = str;
        if (formats != null) {
            val = new Formatter().format(Locale.getDefault(), str, formats).toString();
        }
        if (this.outLogApi != null) {
            this.outLogApi.out(val);
            System.out.println(val);
        } else {
            System.out.println(val);
        }

    }


}


